package com.zcx.qshop.activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zcx.helper.bound.BoundView;
import com.zcx.helper.util.UtilApp;
import com.zcx.helper.util.UtilToast;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.R;
import com.zcx.qshop.action.LoginAction;
import com.zcx.qshop.conn.JsonUserAsyGet;
import com.zcx.qshop.dialog.WhetherDialog;
import com.zcx.qshop.view.TitleView;

/**
 * Created by Administrator on 2015/8/22 0022.
 */
public class SettingActivity extends QSActivity implements View.OnClickListener {

    @BoundView(R.id.title_view) private TitleView titleView;

    @BoundView(R.id.setting_about_clear) private View clear;

    @BoundView(R.id.setting_about_us) private View aboutUs;

    @BoundView(R.id.setting_about_call) private ViewGroup call;

    @BoundView(R.id.setting_exit) private View exit;

    private LoginAction.OnLoginStateListener onLoginStateListener = new LoginAction.OnLoginStateListener() {

        @Override
        public void onLogin(JsonUserAsyGet.Info info) {

            exit.setVisibility(View.VISIBLE);

        }

        @Override
        public void onExit() {

            exit.setVisibility(View.GONE);

        }

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_setting);

        titleView.showStyle(TitleView.Style.FULL);

        titleView.showType(TitleView.Type.BACK_TWO, TitleView.Type.NAME_ONE);

        titleView.setTitleName("设置");

        titleView.setOnTitleItemClickListener(new TitleView.OnTitleItemClickListener() {

            @Override
            public void onBackClick() {

                finish();

            }

        });

        clear.setOnClickListener(this);

        aboutUs.setOnClickListener(this);

        call.setOnClickListener(this);

        exit.setOnClickListener(this);

        QSApplication.LoginAction.addOnLoginStateListener(onLoginStateListener);

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){

            case R.id.setting_about_clear:

                new WhetherDialog(this, "清除缓存"){

                    @Override
                    protected void onYes() {

                        UtilToast.show(getContext(), "清除缓存成功");

                    }

                }.show();

                break;

            case R.id.setting_about_us:

                startVerifyActivity(AboutUsActivity.class);

                break;

            case R.id.setting_about_call:

                UtilApp.call(this, ((TextView)call.getChildAt(1)).getText().toString());

                break;

            case R.id.setting_exit:

                QSApplication.LoginAction.exit();

                finish();

                break;

        }

    }

    @Override
    protected void onDestroy() {

        QSApplication.LoginAction.removeOnLoginStateListener(onLoginStateListener);

        super.onDestroy();

    }
}
